package cn.wolfcode.luowowo.mgrsite.web;

import cn.wolfcode.luowowo.article.domain.TravelContent;
import cn.wolfcode.luowowo.article.query.TravelsQuery;
import cn.wolfcode.luowowo.article.service.ITravlesService;
import cn.wolfcoe.luowowo.common.util.AjaxResult;
import com.alibaba.dubbo.config.annotation.Reference;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("travel")
public class TravelController {

    @Reference
    private ITravlesService travlesService;

    @RequestMapping("/list")
    public String travels(Model model, @ModelAttribute("qo") TravelsQuery qo) {
        qo.setIsPublic( true );
        if (qo.getState() == null) {
            int[] state = {1, 3};
            qo.setState( state );
        }
        qo.setOrderType( "t.releaseTime desc" );
        PageInfo pageInfo = travlesService.query( qo );
        model.addAttribute( "pageInfo", pageInfo );
        return "travel/list";
    }

    @RequestMapping("/updateState")
    @ResponseBody
    public Object updateState(Long id, int state) {
        travlesService.updateState(id,state);
        return AjaxResult.SUCCESS;
    }
    @RequestMapping("/getContent")
    @ResponseBody
    public String getContTent(Long id) {
        TravelContent content = travlesService.queryContent( id );
        return content.getContent();
    }

}

